package com.atguigu.dga.governance.assessor;


import com.atguigu.dga.ds.bean.TDsTaskInstance;
import com.atguigu.dga.governance.bean.AssessParam;
import com.atguigu.dga.governance.bean.GovernanceAssessDetail;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

import static com.atguigu.dga.common.constants.CommonConst.DS_TASK_STATE_SUCCESS;

@Component("TASK_FAILED")
public class TaskFailedAssessor extends Assessor{



    @Override
    public void checkProblem(AssessParam assessParam, GovernanceAssessDetail governanceAssessDetail) throws Exception {
        List<TDsTaskInstance> tDsTaskInstanceList = assessParam.getTDsTaskInstanceList();
        if(tDsTaskInstanceList==null){
            return;
        }
        for (TDsTaskInstance tDsTaskInstance : tDsTaskInstanceList) {
            if(!tDsTaskInstance.getState().toString().equals(DS_TASK_STATE_SUCCESS)){
                governanceAssessDetail.setAssessScore(BigDecimal.ZERO);
                governanceAssessDetail.setAssessProblem("存在失败任务："+tDsTaskInstance.getId());
                return;
            }
        }

    }
}
